
package com.funo.government.info.utils;

import java.util.ArrayList;

import com.funo.government.info.bean.AboutInfo;
import com.funo.government.info.bean.AreaInfo;
import com.funo.government.info.bean.NavItem;
import com.funo.government.info.bean.NoticeItem;
import com.funo.government.info.bean.PushInfo;
import com.funo.government.info.bean.VersionInfo;

public class GovernmentResolver extends BusinessResolver {
    private static final String URL_AREA_LIST = DOMAIN + "/inter!arealist.action";

    private static final String URL_NAV_LIST = DOMAIN + "/inter!area.action";

    private static final String URL_NOTICE_LIST = DOMAIN + "/inter!notice.action";

    private static final String URL_PUSH = DOMAIN + "/inter!send.action";

    private static final String URL_VERSION = DOMAIN + "/inter!version.action";

    private static final String URL_ABOUT = DOMAIN + "/inter!about.action";

    /**
     * 获取区域列表
     * 
     * @param callback
     * @return
     */
    public static RequestTask areaList(BusinessCallback<ArrayList<AreaInfo>> callback) {

        RequestTask task = new RequestTask(callback);
        BusinessRequest request = new BusinessRequest(BusinessRequest.REQUEST_TYPE_GET,
                BusinessRequest.RESULT_TYPE_LIST);
        request.url = URL_AREA_LIST;
        request.cls = AreaInfo.class;
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, request);
        return task;
    }

    /**
     * 获取导航
     * 
     * @param areaId
     * @param callback
     * @return
     */
    public static RequestTask navList(String areaId, BusinessCallback<ArrayList<NavItem>> callback) {

        RequestTask task = new RequestTask(callback);
        BusinessRequest request = new BusinessRequest(BusinessRequest.REQUEST_TYPE_GET,
                BusinessRequest.RESULT_TYPE_LIST);
        request.url = URL_NAV_LIST + "?areaId=" + areaId;
        request.cls = NavItem.class;
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, request);
        return task;
    }

    /**
     * 获取通知
     * 
     * @param areaId
     * @param page
     * @param size
     * @param callback
     * @return
     */
    public static RequestTask noticeList(String areaId, int page, int size,
            BusinessCallback<ArrayList<NoticeItem>> callback) {

        RequestTask task = new RequestTask(callback);
        BusinessRequest request = new BusinessRequest(BusinessRequest.REQUEST_TYPE_GET,
                BusinessRequest.RESULT_TYPE_LIST);
        StringBuilder sb = new StringBuilder();
        sb.append(URL_NOTICE_LIST).append("?areaId=").append(areaId).append("&size=").append(size)
                .append("&current=").append(page);
        request.url = sb.toString();
        request.cls = NoticeItem.class;
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, request);
        return task;
    }

    public static RequestTask getPush(String areaId, BusinessCallback<PushInfo> callback) {

        RequestTask task = new RequestTask(callback);
        BusinessRequest request = new BusinessRequest(BusinessRequest.REQUEST_TYPE_GET,
                BusinessRequest.RESULT_TYPE_OBJECT);
        StringBuilder sb = new StringBuilder();
        sb.append(URL_PUSH).append("?areaId=").append(areaId);
        request.url = sb.toString();
        request.cls = PushInfo.class;
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, request);
        return task;
    }

    public static RequestTask getVersion(BusinessCallback<VersionInfo> callback) {

        RequestTask task = new RequestTask(callback);
        BusinessRequest request = new BusinessRequest(BusinessRequest.REQUEST_TYPE_GET,
                BusinessRequest.RESULT_TYPE_OBJECT);
        request.url = URL_VERSION;
        request.cls = VersionInfo.class;
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, request);
        return task;
    }

    public static RequestTask getAbout(BusinessCallback<AboutInfo> callback) {

        RequestTask task = new RequestTask(callback);
        BusinessRequest request = new BusinessRequest(BusinessRequest.REQUEST_TYPE_GET,
                BusinessRequest.RESULT_TYPE_OBJECT);
        request.url = URL_ABOUT;
        request.cls = AboutInfo.class;
        task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, request);
        return task;
    }

}
